package com.fick.tags;

import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fick.hibernate.dao.NewsDAO;
import com.fick.hibernate.model.News;

/**
 * 显示指定栏目第一条
 * 
 * @author 王浩强 2009-08-14
 * 
 * 
 * **/
public class NewsOneTag extends TagSupport {
	private static Log log = LogFactory.getLog(NewsOneTag.class);

	// 栏目id
	private int channelid = 0;

	@Override
	public int doStartTag() throws JspException {

		try {
			StringBuffer sb = new StringBuffer("");
			NewsDAO dao = new NewsDAO();
			List<News> list = dao.findPageByHql("where isAss='1' and channelid.channelId=" + channelid
					+ " order by addDate desc", 1, 1);
			if (list != null && list.size() > 0) {
				News news = list.get(0);
				sb.append("<h1>");
				sb.append(news.getTitle());
				sb.append("</h1>");
				sb.append(news.getContent());
			}
			JspWriter out = pageContext.getOut();
			out.println(sb.toString());
			out.flush();
		} catch (IOException e) {
			log.error("标签显示错误" + e);
			e.printStackTrace();
		}
		return SKIP_BODY;
	}

	public int getChannelid() {
		return channelid;
	}

	public void setChannelid(int channelid) {
		this.channelid = channelid;
	}
}
